package com.dominator.utils.dao;

import com.dominFramework.core.builder.asset.DriverManagerOpt;
import com.dominFramework.core.builder.metainfo.DBMetaInfoUtils;
import com.dominFramework.core.builder.resources.DaoBuilder;
import com.dominFramework.core.dao.asset.DBType;
import com.dominFramework.core.typewrap.Dto;
import com.dominFramework.core.typewrap.Dtos;
import com.dominator.utils.system.PropertiesLoader;

import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;


/**
 * 数据访问层代码生成器
 * 
 * <p>
 *
 * 
 * @author xiongchun
 * @throws SQLException 
 */
public class DaoConsole {


	public static PropertiesLoader propertiesLoader = new PropertiesLoader("sysconfig.properties");


	public static void main(String[] args) throws SQLException {
		//===================
		DriverManagerOpt driverOpt = new DriverManagerOpt();
		//当前版本支持mysql、oracle、sqlserver2005+、H2
		driverOpt.setDataBaseType(DBType.MYSQL);
		driverOpt.setIp(propertiesLoader.getProperty("dao.jdbc.ip"));
		driverOpt.setPort(propertiesLoader.getProperty("dao.jdbc.port"));
		//数据库名或数据库实例名
		driverOpt.setCatalog(propertiesLoader.getProperty("dao.jdbc.catalog"));
		driverOpt.setUserName(propertiesLoader.getProperty("dao.jdbc.username"));
		driverOpt.setPassword(propertiesLoader.getProperty("dao.jdbc.password"));
		//===================
		Dto dto = Dtos.newDto();
		//改为自己存放相关文件的磁盘文件路径
		//dto.put("outPath", "F:/java/project/svn/fenful-api/src/main/java/com/dominator/mybatis/dao");
		dto.put("outPath", "D:/svn/fenful-api/src/main/java/com/dominator/mybatis/dao");


		
		//改为自己相关文件的包路径
		dto.put("package", "com.dominator.mybatis.dao");
		//作者
		dto.put("author", "dominator_ap");
		// 三个模板所在路径
		dto.put("PO_JAVA_VM","/vm/po.java.vm");
		dto.put("DAO_JAVA_VM","/vm/dao.java.vm");
		dto.put("DAO_XML_VM","/vm/dao.xml.vm");

//		//指定多张表请用逗号分隔，不指定则全数据库生成不包括aos开头表和demo开头表；
//		//!!表名区分大小写的喔
//		//dto.put("tables", "aos_module, aos_org, aos_role, aos_role_module, aos_user_role,aos_cmp,aos_icon");
		dto.put("tables", "t_gua_ticket,t_game_order,t_box");



//		//===================
//		Connection connection = DBMetaInfoUtils.newConnection(driverOpt);
//		DaoBuilder.buildDao(connection, dto);
//		connection.close();

		Connection connection = DBMetaInfoUtils.newConnection(driverOpt);
		DaoBuilder.buildDao(connection, dto);
		connection.close();


		System.out.println("生成完毕，请刷新项目");
	}

}
